# -*- coding: utf-8 -*-

import json
import logging

from flask import Flask, request

flask_app_log = 'flask.app'
logger = logging.getLogger(flask_app_log)
app = Flask(__name__)


@app.route('/')
def index():
    resp = "index"
    logger.debug(resp)
    return resp


@app.route(rule='/get', methods=['GET'])
def get():
    key = request.args.get('key', 'value')
    param = request.args.get('param', 'parameter')
    data = {"key": key, "param": param}
    logger.info(data)
    return data


@app.route(rule='/post', methods=['POST'])
def post():
    data: bytes = request.data
    data_dict: dict = json.loads(data)
    return data


@app.route(rule='/post_json', methods=['POST'])
def post_json():
    json_dict: dict = request.json
    value = json_dict.get('key')
    logger.info(f'value:{value}')
    return json_dict


if __name__ == '__main__':
    """
    curl "http://127.0.0.1:5000/"
    curl "http://127.0.0.1:5000/get?key=value&param=parameter"
    curl "http://127.0.0.1:5000/post" -X POST -H "Content-Type: application/json" -d '{"key": "value"}'
    """
    app.debug = True
    app.run(threaded=True)
    pass
